package thread;

public class ThreadDemo2 {
    public static void main(String[] args) {
        //使用匿名内部类创建线程，实现线程解耦
        MyRunnable r = new MyRunnable();
        Thread t1 = new Thread(r, "线程1");//创建线程1
        t1.start();

        //使用匿名内部类创建线程，实现线程解耦
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i <= 100; i++) {
                    System.out.println(Thread.currentThread().getName() + ":" +i);
                }
            }
        }, "线程2");
        t2.start();

        //改写为lambda
        Thread t3 = new Thread(() -> {
            for (int i = 1; i <= 100; i++) {
                System.out.println(Thread.currentThread().getName() + ":" +i);
            }
        });
        t3.start();

    }
}
class MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i = 1; i <= 100; i++) {
            System.out.println(Thread.currentThread().getName() + ":" +i);
        }
    }
}

